package com.xyht.sca_s.student_manage_system.modules.enrolStudent.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonCodeEnum;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonResult;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.enrolStudent.entity.req.SmsEnrolStudentBatchReq;
import com.xyht.sca_s.student_manage_system.modules.enrolStudent.entity.req.SmsEnrolStudentDeleteReq;
import com.xyht.sca_s.student_manage_system.modules.enrolStudent.entity.req.SmsEnrolStudentUpdateReq;
import com.xyht.sca_s.student_manage_system.modules.enrolStudent.service.SmsEnrolStudentService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.concurrent.Future;

/**
 * <p>
 * 招生信息表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-08-31
 */
@RestController
@RequestMapping("/enrolStudent")
@SecretBody
public class SmsEnrolStudentController {

    @Resource
    private SmsEnrolStudentService smsEnrolStudentService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty(value = "招生信息批量导入")
    @PostMapping("/batch/add")
    public ResponseResult batchAddEnrolStudent(@RequestBody Map<String,Object> map, HttpServletRequest request){
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        ResponseResult commonCodeEnum;
        try{
            Future<ResponseResult> future = smsEnrolStudentService.batchAddEnrolStudent(map,user_id);
            while (true){
                if (future.isDone()){
                    commonCodeEnum = future.get();
                    break;
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            return CommonResult.failed(CommonCodeEnum.FAIL);
        }
        return commonCodeEnum;
    }

    @ApiModelProperty(value = "招生信息批量删除")
    @PostMapping("/delete")
    public ResponseResult deleteEnrolStudentInfo(@RequestBody SmsEnrolStudentDeleteReq deleteReq){
        return smsEnrolStudentService.deleteEnrolStudentInfo(deleteReq);
    }

    @ApiModelProperty(value = "新增招生信息")
    @PostMapping("/add")
    public ResponseResult addEnrolStudentInfo(@RequestBody SmsEnrolStudentBatchReq addReq){
        return smsEnrolStudentService.addEnrolStudentInfo(addReq);
    }

    @ApiModelProperty(value = "修改招生信息")
    @PostMapping("/update")
    public ResponseResult updateEnrolStudentInfo(@RequestBody SmsEnrolStudentUpdateReq updateReq){
        return smsEnrolStudentService.updateEnrolStudentInfo(updateReq);
    }

    @ApiModelProperty(value = "查看招生信息")
    @GetMapping("/id")
    public ResponseResult getEnrolStudentInfoById(@RequestParam(value = "id",required = false) String id){
        return smsEnrolStudentService.getEnrolStudentInfoById(id);
    }

    @ApiModelProperty(value = "查看招生信息")
    @GetMapping("/list")
    public ResponseResult getEnrolStudentInfoList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                  @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                  @RequestParam(value = "name",required = false) String name,
                                                  @RequestParam(value = "idCard",required = false) String idCard,
                                                  @RequestParam(value = "sex",required = false) Integer sex,
                                                  @RequestParam(value = "origin",required = false) String origin,
                                                  @RequestParam(value = "nation",required = false) String nation,
                                                  @RequestParam(value = "college",required = false) String college){
        return smsEnrolStudentService.getEnrolStudentInfoList(pageNum,pageSize,name,idCard,sex,origin,nation,college);
    }


}

